﻿
@inject IPluginFinder pluginFinder
@inject IPermissionService permissionService
@using Urs.Services.Security;
@using Urs.Framework.Menu;
@using Urs.Services.Plugins;
@using Microsoft.AspNetCore.Routing
@{
    //load sitemap
    var siteMap = new Urs.Framework.Menu.XmlSiteMap();
    siteMap.LoadFrom("~/Areas/Admin/sitemap.config");

}

<div class="layui-side layui-bg-black layuimini-menu-left">
    <ul class="layui-nav layui-nav-tree layui-this" layuimini-tab-tag="no" lay-filter="layadmin-system-side-menu">
        @{
            //standard (default) items
            var rootNode = siteMap.RootNode;

            //plugins
            var adminMenuPlugins = pluginFinder.GetPlugins<IAdminMenuPlugin>().ToList();
            foreach (var adminMenuPlugin in adminMenuPlugins)
            {
                adminMenuPlugin.ManageSiteMap(rootNode);
            }
            //"Plugins" menu item should be visible when it has some child nodes
            var pluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "Third party plugins");
            if (pluginNode != null && pluginNode.Visible)
            {
                var hasManagePluginsPermission = permissionService.Authorize(StandardPermissionProvider.ManagePlugins);
                pluginNode.Visible = hasManagePluginsPermission && pluginNode.ChildNodes.Any(x => x.Visible);
            }
        }
        @foreach (var item in siteMap.RootNode.ChildNodes.Where(x => x.Visible))
        {
            @await Html.PartialAsync("_MenuItem", item)
        }
    </ul>
</div>

